
#ifndef ___WORK_THREAD_H
#define ___WORK_THREAD_H

class WorkThread
{
	HANDLE thread;

	bool  run;
	const Settings		settings;
	WorkLoad *workLoad;

public:

	WorkThread(const Settings &_settings, WorkLoad *_workLoad )
		:	run(true),
			settings(_settings),
			workLoad(_workLoad) {

		Initialise();
	}

	virtual ~WorkThread() {

		CleanUp();
	}

	DWORD Go() {

		while(run)
			workLoad->DoSomeWork();
		
		return 0;
	}

	static DWORD WINAPI ThreadMain(LPVOID lpParameter) {

		WorkThread *t = (WorkThread*)lpParameter;

		return t->Go();
	}

private:

	void Initialise() {

		thread = CreateThread(NULL,0, WorkThread::ThreadMain, (LPVOID)this, 0, 0);

	}

	void CleanUp() {

		run = false;

		WaitForSingleObject( thread, INFINITE );

		CloseHandle( thread );
	}
};

#endif /*** __WORK_THREAD_H ***/

